package com.cskaoyan.mall.user.controller;

import com.cskaoyan.mall.user.converter.UserAddressConverter;
import com.cskaoyan.mall.user.dto.UserAddressDTO;
import com.cskaoyan.mall.user.model.UserAddress;
import com.cskaoyan.mall.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用于接收其他服务的请求，并返回相应的数据
 * @author Macro_Ray
 * @since 2024/6/19 下午2:58
 */
@RestController
public class UserApiController {

    @Autowired
    UserAddressConverter userAddressConverter;
    @Autowired
    UserService userService;

    /**根据用户id获取用户地址列表*/
    @GetMapping("/api/user/inner/findUserAddressListByUserId/{userId}")
    public List<UserAddressDTO> findUserAddressListByUserId(@PathVariable("userId") String userId){
        List<UserAddress> userAddressList = userService.findUserAddressListByUserId(userId);
        return userAddressConverter.userAddressPOs2DTOs(userAddressList);
    }

}
